package com.huike.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huike.entity.Department;
import com.huike.mapper.DepartmentMapper;
import com.huike.service.DepartmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
// ctrl +i
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;


    @Override
    public List<Department> getAll() {
        List<Department> all = departmentMapper.getAll();
        System.out.println(all);
        return all;
    }

    @Override
    public PageInfo<Department> getPage(int currentPage, int pageSize) {
        // 1. 查询数据之前调PageHelper.startPage
        // 2. 数据库查询
        // 3. 将查询结果放到PageInfo
        PageHelper.startPage(currentPage,pageSize);
        List<Department> all = departmentMapper.getAll();
        return new PageInfo<>(all);
    }

    @Override
    public int addDept(Department department) {

        return departmentMapper.addDept(department);
    }

    @Override
    public int saveOrUpdate(Department department) {
        return departmentMapper.saveOrUpdate(department);
    }

    @Override
    public int deleteDept(Integer id) {
        return departmentMapper.deleteDept(id);
    }
}
